//
//  SSSPersonCenterController.m
//  SSSMerchant
//
//  Created by Darker on 2017/3/20.
//  Copyright © 2017年 xnxin. All rights reserved.
//

#import "SSSPersonCenterController.h"
#import "commonCell.h"
#import "SSSSetUpController.h"
#import "RecommendedFeedbackController.h"
#import "exchangeCenterController.h"
#import "SSSRecommendController.h"
#import "AboutOurController.h"

@interface SSSPersonCenterController ()<UITableViewDelegate,UITableViewDataSource>

{
    NSArray *_titleArray;
    UITableView * _bgTableView;//tableView
    UIView *_headerVeiw;//头部视图

}

@end

static NSString * const PersonalID = @"PersonalCell";

@implementation SSSPersonCenterController

- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    self.title = @"个人中心";
    self.view.backgroundColor = [UIColor colorWithHex:@"F9F9FA"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化数据源
    _titleArray = @[@"推广中心",@"兑换中心",@"设置",@"关于我们",@"建议反馈",@"联系客服"];
    [self initHeaderVeiw];
    [self initBgTableView];
}
- (void)initHeaderVeiw{
    
    _headerVeiw = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KSCREEN_Width, HeigthIos6CompeteWithCurrent(132))];
    _headerVeiw.backgroundColor = [UIColor colorWithHex:@"F9F9FA"];
    UIImageView *userHeaderImageView = [[UIImageView alloc]init];
    userHeaderImageView.image = [UIImage imageNamed:@"icon_headportrait"];
    [_headerVeiw addSubview:userHeaderImageView];
    userHeaderImageView.sd_layout
    .centerYEqualToView(_headerVeiw)
    .leftSpaceToView(_headerVeiw,WidthIos6CompeteWithCurrent(45))
    .heightIs(WidthIos6CompeteWithCurrent(84))
    .widthIs(WidthIos6CompeteWithCurrent(84));
    userHeaderImageView.layer.masksToBounds = YES;
    userHeaderImageView.layer.cornerRadius = userHeaderImageView.frame.size.height/2;
    
    UIView *centerView = [[UIView alloc]init];
    [_headerVeiw addSubview:centerView];
    centerView.sd_layout
    .leftSpaceToView(userHeaderImageView,WidthIos6CompeteWithCurrent(20))
    .centerYEqualToView(userHeaderImageView)
    .rightSpaceToView(_headerVeiw,0)
    .heightIs(HeigthIos6CompeteWithCurrent(40));
    
    UILabel *nameLabel = [[UILabel alloc]init];
    nameLabel.text = @"商家名：米老师";
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    nameLabel.font = [SSSFont systemFontOfSize:15];
    [centerView addSubview:nameLabel];
    nameLabel.sd_layout
    .leftEqualToView(centerView)
    .topEqualToView(centerView)
    .rightEqualToView(centerView)
    .heightIs(centerView.frame.size.height/2);
    
    //手机号
    UILabel *phoneNuLabel = [[UILabel alloc]init];
    phoneNuLabel.text = @"手机号：18080087309";
    phoneNuLabel.textAlignment = NSTextAlignmentLeft;
    phoneNuLabel.textColor = [UIColor colorWithHex:@"6D6D6D"];
    phoneNuLabel.font = [SSSFont systemFontOfSize:15];
    [centerView addSubview:phoneNuLabel];
    phoneNuLabel.sd_layout
    .leftEqualToView(centerView)
    .topSpaceToView(nameLabel,0)
    .rightEqualToView(centerView)
    .heightIs(centerView.frame.size.height/2);
    
    
}
#pragma mark - 初始化tableView
- (void)initBgTableView{
    
    _bgTableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, FSCREEN_Width, HeigthIos6CompeteWithCurrent(50)*_titleArray.count + HeigthIos6CompeteWithCurrent(132)+64) style:UITableViewStylePlain];
    _bgTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _bgTableView.backgroundColor = [UIColor clearColor];
    _bgTableView.tableHeaderView = _headerVeiw;
    _bgTableView.delegate = self;
    _bgTableView.dataSource = self;
    _bgTableView.rowHeight = HeigthIos6CompeteWithCurrent(50);
    _bgTableView.scrollEnabled = NO;
    [self.view addSubview:_bgTableView];
    
}
#pragma amrk - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _titleArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    Class currentClass = [commonCell class];
    
    commonCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(currentClass)];
    if (!cell) {
        cell = [[commonCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:PersonalID];
    }
    cell.nameLabel.text = _titleArray[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //cell.nameLabel.text = _selectedDataArray[indexPath.row];
    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0) {
        
        SSSRecommendController *recommendVc = [[SSSRecommendController alloc]init];
        [self.navigationController pushViewController:recommendVc animated:YES];
        
    }else if(indexPath.row == 1) {
        
        exchangeCenterController *exchangeVc = [[exchangeCenterController alloc]init];
        [self.navigationController pushViewController:exchangeVc animated:YES];
        
    }else if (indexPath.row == 2) {
        SSSSetUpController *setVc = [[SSSSetUpController alloc]init];
        [self.navigationController pushViewController:setVc animated:YES];
        
        
    }else if (indexPath.row == 3){
        
        AboutOurController *aboVc = [[AboutOurController alloc]init];
        [self.navigationController pushViewController:aboVc animated:YES];
        
    }else if (indexPath.row == 4){
        
        RecommendedFeedbackController *recommendVc = [[RecommendedFeedbackController alloc]init];
        [self.navigationController pushViewController:recommendVc animated:YES];
        
    }else if (indexPath.row == _titleArray.count -1){
        
        
        UIWebView * callWebview = [[UIWebView alloc] init];
        NSMutableString * str =[[NSMutableString alloc] initWithFormat:@"tel:%ld",18783898735];
        [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
        [self.view addSubview:callWebview];
        
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    
    
}
@end
